package com.yql.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yql.dao.OrderDao;
import com.yql.entity.*;
import com.yql.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderDao orderDao;
    @Override
    public List<Menu> getTree(User user) {
        if (user!=null){
            return orderDao.getTree(user.getMid());
        }
        return null;
    }

    @Override
    public User login(User user) {
        return orderDao.login(user);
    }

    @Override
    public PageInfo<Order> listOrder(OrderVO vo, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Order> list = orderDao.listOrder(vo);
        return new PageInfo<>(list);
    }

    @Override
    public void addOrder(Order order) {
        orderDao.addOrder(order);
        List<Goods> goodsList = order.getGoodsList();
        Long outNum = order.getOutNum();
        if(goodsList!=null && goodsList.size()>0){
            for (Goods goods : goodsList) {
                goods.setOid(outNum);
                orderDao.addGoods(goods);
            }
        }

    }
}
